package com.itheima.mapper;

import com.itheima.pojo.Clazz;
import com.itheima.pojo.ClazzQueryParam;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;


@Mapper
public interface ClazzMapper {
//    查询所有班级
    @Select("select * from clazz")
    public List<Clazz> searchAll();


    List<Clazz> lists(ClazzQueryParam clazzQueryParam);


    @Delete("delete from clazz where id=#{id}")
    void deleteByIds( Integer id);

    @Select("select * from clazz where id=#{id}")
    Clazz getById(Integer id);

    @Update("update clazz set name=#{name},room=#{room},begin_date=#{beginDate},end_date=#{endDate},master_id=#{masterId},subject=#{subject},update_time=#{updateTime} where id=#{id}")
    void update(Clazz clazz);

    @Insert("insert into clazz(name,room,begin_date,end_date,master_id,subject,update_time) values(#{name},#{room},#{beginDate},#{endDate},#{masterId},#{subject},#{updateTime})")
    void insert(Clazz clazz);

    @MapKey("name")
    List<Map<String, Object>> countClazzData();

    //查询该班级的学生人数
    @Select("select count(id) from student where clazz_id=#{clazzId}")
    Integer countStudentByClazzId(Integer clazzId);
}

